class Grammar
    attr_accessor :rules, :start_nonterm

    def initialize(rules, start_nonterm)
        @rules = rules
        @start_nonterm = start_nonterm
    end

    def print
        for rule in rules
            rule.print
        end
    end
end

class Rule
    def print
    end
end

class FirstTypeRule < Rule
    attr_accessor :nonterm, :term

    def initialize(nonterm, term)
        @nonterm = nonterm
        @term = term
    end
    
    def print
        puts @nonterm.name + " -> " + @term.name
    end
end

class SecondTypeRule < Rule
    attr_accessor :nonterm, :term, :nonterm2

    def initialize(nonterm, term, nonterm2)
        @term = term
        @nonterm = nonterm
        @nonterm2 = nonterm2
    end
    
    def print
        puts @nonterm.name + " -> " + @term.name + @nonterm2.name
    end
end

class ThirdTypeRule < Rule
    attr_accessor :nonterm

    def initialize(nonterm)
        @nonterm = nonterm
    end
    
    def print
        puts @nonterm.name + " -> epsilon" 
    end
end

class Terminal
    attr_accessor :name

    def initialize(name)
        @name = name
    end
end

class Nonterminal
    attr_accessor :name

    def initialize(name)
        @name = name
    end
end
